package com.itoffer.web.old;

import com.itoffer.pojo.ResumeBasicInfo;
import com.itoffer.service.ResumeService;
import com.itoffer.service.impl.ResumeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * 更新简历信息
 */
//@WebServlet("/updateResumeServlet")
public class UpdateResumeServlet extends HttpServlet {
    private ResumeService resumeService = new ResumeServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;chart = utf-8");
        resp.setCharacterEncoding("utf-8");
        int basicinfo_id = Integer.parseInt(req.getParameter("basicinfo_id"));
        String realname = req.getParameter("realname");
        String gender = req.getParameter("gender");
        String birthday = req.getParameter("birthday");
        String telephone = req.getParameter("telephone");
        String email = req.getParameter("email");
        String job_intension = req.getParameter("job_intension");
        String job_experience = req.getParameter("job_experience");

        //封装对象
        //创建一个Resume对象
        ResumeBasicInfo r = new ResumeBasicInfo();
        r.setBasicinfo_id(basicinfo_id);
        r.setRealname(realname);
        r.setGender(gender);
        r.setBirthday(birthday);
        r.setTelephone(telephone);
        r.setEmail(email);
        r.setJob_intension(job_intension);
        r.setJob_experience(job_experience);

        //调用业务层修改方法来进行修改
        boolean b = resumeService.updateResume(r);

        //再查询出来刷新后的值
        ResumeBasicInfo basicInfo = resumeService.selectCurrentResume(basicinfo_id);
        if(b){
            HttpSession session = req.getSession();
            session.setAttribute("basicInfo",basicInfo);
            String contextPath = req.getContextPath();
            resp.sendRedirect(contextPath+"/applicant/resume.jsp");
        }else {
            //修改失败，跳转到错误页面
            String contextPath = req.getContextPath();
            resp.sendRedirect(contextPath+"/error.jsp");
        }


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
